package com.emspost.utils;

import cn.hutool.core.collection.SpliteratorUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.unit.DataUnit;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

public class TimeUtilTest {
    public static void main(String[] args) {

        DateTime dateTime = DateUtil.lastWeek();
        System.out.println(dateTime);
        int i = DateUtil.thisWeekOfYear();
        System.out.println(i - 1 );


        DateTime parse = DateUtil.parse("2025-08-11");
        //获取当前日期
        int weekInt = DateUtil.dayOfWeek(parse);
        //时间不等于周一不执行该定时任务
        if (weekInt != 2) {
            System.out.println("不是周一，不执行该定时任务");
            return;
        }
        //上周统计时间
        java.util.Date startTime = DateUtil.beginOfDay(DateUtil.lastWeek()).toJdkDate();
        System.out.println("start" + startTime);
        Date endTime = DateUtil.beginOfDay(parse).toJdkDate();
        System.out.println("end" + endTime);

        DateTime now = DateUtil.parse(DateUtil.now());
        // 获取昨天的日期
        DateTime yesterday = DateUtil.offsetDay(now, -1);
        Date startTime1 = DateUtil.beginOfDay(yesterday).toJdkDate();
        System.out.println("ceshi1" + startTime1);
        Date endTime2 = DateUtil.beginOfDay(now).toJdkDate();
        System.out.println("ceshi2" + endTime2);
        String now2 = DateUtil.now();
        DateTime now1 = DateUtil.offsetDay(DateUtil.parse(now2),-1);
        System.out.println("now1" + now1);
        Date monthStartTime = DateUtil.beginOfDay(DateUtil.beginOfMonth(DateUtil.lastMonth())).toJdkDate();
        System.out.println("monthStartTime" + monthStartTime);
        Date monthEndTime = DateUtil.beginOfDay(DateUtil.beginOfMonth(now1)).toJdkDate();
        System.out.println("monthEndTime" + monthEndTime);

        DateTime nowaa = DateTime.now();
        //上周统计时间
        Date startTimeaa = DateUtil.beginOfDay(DateUtil.beginOfMonth(DateUtil.lastMonth())).toJdkDate();
        System.out.println("startTimeaa" + startTimeaa);
        Date endTimeaa = DateUtil.beginOfDay(DateUtil.beginOfMonth(now)).toJdkDate();
        System.out.println("endTimeaa" + endTimeaa);
        System.out.println("==========================");

        DateTime weekNow = DateTime.now();
        //上周统计时间
        Date weekStartTime = DateUtil.beginOfDay(DateUtil.lastWeek()).toJdkDate();
        System.out.println("weekStartTime" + weekStartTime);
        Date weekEndTime = DateUtil.endOfDay(DateUtil.offsetDay(weekNow, -1)).toJdkDate();
        System.out.println("weekEndTime" + weekEndTime);

        System.out.println("==========================");


        DateTime monthDateTime = DateTime.of("2025-08-01 07:00:00", "yyyy-MM-dd HH:mm:ss");
        //上月统计时间
        Date monthStartTime1 = DateUtil.beginOfDay(DateUtil.beginOfMonth(DateUtil.lastMonth())).toJdkDate();
        System.out.println("monthStartTime1" + monthStartTime1);
        Date monthEndTime1 = DateUtil.endOfDay(DateUtil.offsetDay(monthDateTime, -1)).toJdkDate();
        System.out.println("monthEndTime1" + monthEndTime1);

        System.out.println("==========================");

    }
}
